﻿using System;
using PetaPoco;
using PmSoft;
using PmSoft.Caching;
using PmSoft.Entity;
using PmSoft.Logging;

namespace Modules
{
    /// <summary>
    /// 表操作日志
    ///</summary>
    [TableName("sys_table_logs")]
    [PrimaryKey("id", AutoIncrement = true)]
    [CacheSetting(true)]
    [Serializable]
    public class SysTableLog : IEntity
    {

        public SysTableLog()
        {

        }

        public SysTableLog(IUser user)
        {
            UserId = user.Id;
            SecurityId = user.SecurityId;
            UserType = user.Type;
            Operator = user.Name;
        }

        /// <summary>
        /// 日志主键 
        ///</summary>
        [Column("id")]
        public int Id { get; set; }
        /// <summary>
        /// 操作类型 
        ///</summary>
        [Column("operation_type")]
        public EntityOperationType OperationType { get; set; }
        /// <summary>
        /// 数据库名 
        ///</summary>
        [Column("database_name")]
        public string DatabaseName { get; set; }
        /// <summary>
        /// 表名 
        ///</summary>
        [Column("table_name")]
        public string TableName { get; set; }
        /// <summary>
        /// 对象ID 
        ///</summary>
        [Column("object_id")]
        public string ObjectId { get; set; }
        /// <summary>
        /// 操作数据 
        ///</summary>
        [Column("data")]
        public string Data { get; set; }
        /// <summary>
        /// 操作者安全信息ID 
        ///</summary>
        [Column("security_id")]
        public int? SecurityId { get; set; }
        /// <summary>
        /// 操作用户ID 
        ///</summary>
        [Column("user_id")]
        public int UserId { get; set; }
        /// <summary>
        /// 操作用户类型 
        ///</summary>
        [Column("user_type")]
        public UserType UserType { get; set; }
        /// <summary>
        /// 操作者名称 
        ///</summary>
        [Column("operator")]
        public string Operator { get; set; }
        /// <summary>
        /// 操作IP 
        ///</summary>
        [Column("ip")]
        public string Ip { get; set; }
        /// <summary>
        /// 操作URL 
        ///</summary>
        [Column("url")]
        public string Url { get; set; }
        /// <summary>
        /// 创建时间 
        ///</summary>
        [Column("create_time")]
        public DateTime CreateTime { get; set; } = DateTime.Now;

        #region IEntity 成员

        [Ignore]
        object IEntity.EntityId { get { return this.Id; } }

        #endregion

    }
}
